<?php
include_once("Dao/db.php");
Class Login
{
	var $errorMessage;
	
	function mytask()
	{
		// 初期化の場合
		if($_POST["act"] == null)
		{
			$this->errorMessage = "";
		}
		// ログインを押下すると
		else if($_POST["act"] == "submit")
		{
			$this->errorMessage = "";
			$this->checkMemeber();
		}
	}
	
	function checkMemeber()
	{
		$sql = "select memberId,company,management from member where loginid='{$_POST["loginid"]}' and `password`='{$_POST["password"]}' and status = 1";
		
		$result = mysql_query($sql);
		$number_of_rows = mysql_num_rows($result);
		if ($number_of_rows < 1)
		{
			$this->errorMessage = "ユーザー名、パスワードが不正です。";
		}
		else
		{
			$OK = $this->updateLoginDate();
			if($OK == "0")
			{
				return;
			}
			else
			{
				$data = mysql_fetch_row($result);
				session_start();
				$_SESSION["memberId"] = $data[0];			
				$_SESSION["loginId"] = $_POST["loginid"];
				$_SESSION["company"] = $data[1];
				if($data[2] == 1) //Alitoの場合
				{
					header("Location:admin/industry.php");				
				}
				else
				{
					header("Location:report/industry.php");									
				}
			}
		}
	}
	
	function updateLoginDate()
	{
		$sql = "update member set lastloginDate = now() where loginid='{$_POST["loginid"]}' and `password`='{$_POST["password"]}'";
		$result = mysql_query($sql);
		if($result != "1")
		{
			$this->errorMessage = "ログイン時エラーが発生しました。";
			return 0;
		}
	}
}
?>